package com.zzk.lanouhn.myapplication1.adapters;

import android.app.Activity;
import android.content.Context;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.squareup.picasso.Picasso;
import com.zzk.lanouhn.myapplication1.R;
import com.zzk.lanouhn.myapplication1.modles.FindDetailsXiaotuModle;

import java.util.List;

/**
 * Created by lanouhn on 16/9/10.
 */
public class FindDetailsXiaotuAdapter extends RecyclerView.Adapter<FindDetailsXiaotuAdapter.MyXiaotuHorld> {

    private Context context;
    private FindDetailsXiaotuModle modle;

    public FindDetailsXiaotuAdapter(Context context, FindDetailsXiaotuModle modle) {
        this.context = context;
        this.modle = modle;
    }

    @Override
    public MyXiaotuHorld onCreateViewHolder(ViewGroup parent, int viewType) {
        View view = LayoutInflater.from(context).inflate(R.layout.item_actfind_details_xiaotu, null);
        MyXiaotuHorld horld = new MyXiaotuHorld(view);
        return horld;
    }

    @Override
    public void onBindViewHolder(MyXiaotuHorld holder, int position) {

        holder.tv_dazhuzhe.setText(modle.getName());
        holder.tv_xiaozhuzhe.setText(modle.getName());

        Picasso.with(context).load(modle.getImage()).into(holder.iv_zhuzhe);

        if (modle.getGender() == 1) {
            holder.iv_nan.setVisibility(View.VISIBLE);
            holder.iv_nv.setVisibility(View.GONE);
        } else {
            holder.iv_nan.setVisibility(View.GONE);
            holder.iv_nv.setVisibility(View.VISIBLE);
        }

        holder.tv_pianshu.setText(modle.getTrips_count() + "篇游记");

        holder.ll_fanhui.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                ((Activity)context).finish();
            }
        });

    }

    @Override
    public int getItemCount() {
        return 1;
    }

    public class MyXiaotuHorld extends RecyclerView.ViewHolder {

        private TextView tv_dazhuzhe, tv_xiaozhuzhe;
        private ImageView iv_zhuzhe;
        private TextView tv_pianshu;

        private ImageView iv_nan, iv_nv;

        private LinearLayout ll_fanhui;

        public MyXiaotuHorld(View itemView) {
            super(itemView);

            tv_dazhuzhe = (TextView) itemView.findViewById(R.id.find_details_xiaotu_da_zuozhe);
            tv_xiaozhuzhe = (TextView) itemView.findViewById(R.id.find_details_xiaotu_xiao_zuozhe);
            iv_zhuzhe = (ImageView) itemView.findViewById(R.id.find_details_xiaotu_tu);
            tv_pianshu = (TextView) itemView.findViewById(R.id.find_details_xiaotu_pianshu);

            iv_nan = (ImageView) itemView.findViewById(R.id.find_details_xiaotu_nan);
            iv_nv = (ImageView) itemView.findViewById(R.id.find_details_xiaotu_nv);

            ll_fanhui= (LinearLayout) itemView.findViewById(R.id.detailed_find_xiaotu_fanhui);
        }
    }

}
